{% load static %}
{% load notifications_tags %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="/static/base.css">
    <link rel="stylesheet" href="{% static 'bootstrap-3.3.7/css/bootstrap.css' %}">
    <script src="../../static/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="{% static 'bootstrap-3.3.7/js/bootstrap.min.js' %}"></script>
    <!--<script type="text/javascript" src="{% static 'bootstrap.min.js' %}"></script>-->
    <scrtpt type="text/javascript" src="{% static 'notifications/notify.js' %}"></scrtpt>
    {% block header_extends %}{% endblock %}
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="{% url 'home' %}">个人博客网站</a>
            <button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse" id="navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="{% block nav_home_active %}{% endblock %}">
                    <a href="{% url 'home' %}">首页</a>
                </li>
                <li class="{% block nav_blog_active %}{% endblock %}">
                    <a href="{% url 'blog_list' %}">博客</a>
                </li>
            </ul>

            <ul class="nav navbar-nav navbar-right">
                {% if not user.is_authenticated %}
                <li>
                    {% if request.GET.from %}
                    <a href="{% url 'login' %}?from={{ request.GET.from }}">登录</a>
                    {% else %}
                    <a href="{% url 'login' %}?from={{ request.get_full_path }}">登录</a>
                    {% endif %}
                </li>
                <li>
                    {% if request.GET.from %}
                    <a href="{% url 'register' %}?from={{ request.GET.from }}">注册</a>
                    {% else %}
                    <a href="{% url 'register' %}?from={{ request.get_full_path }}">注册</a>
                    {% endif %}
                </li>
                {% else %}
                {% notifications_unread as unread_count %}
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
                        你好,{{ user.get_nickname_or_username }}
                        <span class="badge unread-count live_notify_badge">{% if unread_count > 0 %}{{ unread_count }}{% endif %}</span>
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="{% url 'user_info' %}">个人资料</a></li>
                        <!--<li><a href="{% url 'change_password' %}">修改密码</a></li>-->
                        <li><a href="{% url 'my_notifications' %}">我的消息
                            <span class="badge unread-count live_notify_badge">{% if unread_count > 0 %}{{ unread_count }}{% endif %}</span>
                        </a></li>
                        {% if user.is_staff or user.is_superuser %}
                        <li><a href="{% url 'admin:index' %}">后台管理</a></li>
                        {% endif %}
                        <li><a href="{% url 'logout' %}?from={{ request.get_full_path }}">退出</a></li>
                    </ul>
                </li>
                {% endif %}
                <li>
                    <form class="navbar-form search-form" action="{% url 'search' %}">
                        <div class="form-group">
                            <input type="text" name="wd" class="form-control" placeholder="Search">
                        </div>
                        <button type="submit" class="btn btn-default">
                            <span class="glyphicon glyphicon-search"></span>
                        </button>
                    </form>
                </li>
            </ul>
        </div>
    </div>
</div>

    {% block content %}{% endblock %}
<!-- footer -->
<div class="footer">
    <div class="website-info">
        <p>Copyright©2020 xiaobailong.com 版权所有
            <a href="http://beian.miit.gov.cn">浙ICP备17041146号</a>
        </p>
    </div>
</div>
<script type="text/javascript">
    // 底部栏置底部
    // 窗体改变大小事件
    $(window).resize(function () {
        // 正文高度
        var body_height = $(document.body).outerHeight(true);
        // 底部元素高度
        var bottom_height = $(".footer").outerHeight(true);
        //浏览器页面高度
        var window_height = $(window).height();

        //判断并调整底部元素的样式
        if ($('.footer').hasClass('page-bottom')) {
            // 若包含有page-bottom类，就应用了position设置
            // 当position为absolute时，body高度不包含这个元素
            // 页面高度需要判断body和footer只和若小于浏览器窗口
            // 则移除样式，让footer自然跟随在正文后面
            if (body_height +  bottom_height >= window_height) {
                $('.footer').removeClass('page-bottom');
            }
        } else {
            // 若没有page-bottom类，body高度包含footer
            // 判断body高度小于浏览器时，则悬浮于底部
            if (body_height < window_height) {
                $('.footer').addClass('page-bottom');
                }
            }
    });
    // 页面加载时,模拟触发一下resize事件
    $(window).trigger('resize');

    // 自定义实时获取未读消息
    function my_special_notification_callback(data) {
        unread_count = data['unread_count'];
        if (unread_count == 0) {
            unread_count = '';
        }
        $('live_notify_badge').text(unread_count);
    }

</script>
{% register_notify_callbacks callbacks='my_special_notification_callback' %}
{% block script_extends %}{% endblock %}
</body>
</html>
